// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Bluetooth.BLUETOOTH_SELECT_DEVICE_PARAMS
// 
// Copyright (c) 2003-2006 In The Hand Ltd, All rights reserved.
// This source code is licensed under the In The Hand Community License - see License.txt

using System;
using System.Runtime.InteropServices;

namespace InTheHand.Net.Bluetooth
{
    internal struct BLUETOOTH_SELECT_DEVICE_PARAMS
    {
        int dwSize;
        int cNumOfClasses;
        IntPtr /*BLUETOOTH_COD_PAIRS*/ prgClassOfDevices;
#if V2
        [MarshalAs(UnmanagedType.LPWStr)]
#endif
        public string pszInfo;
        public IntPtr hwndParent;
#if V2
        [MarshalAs(UnmanagedType.Bool)]
#endif
        public bool fForceAuthentication;
#if V2
        [MarshalAs(UnmanagedType.Bool)]
#endif
        public bool fShowAuthenticated;
#if V2
        [MarshalAs(UnmanagedType.Bool)]
#endif
        public bool fShowRemembered;
#if V2
        [MarshalAs(UnmanagedType.Bool)]
#endif
        public bool fShowUnknown;
#if V2
        [MarshalAs(UnmanagedType.Bool)]
#endif
        public bool fAddNewDeviceWizard;
#if V2
        [MarshalAs(UnmanagedType.Bool)]
#endif
        public bool fSkipServicesPage;
        IntPtr pfnDeviceCallback;
        IntPtr pvParam;
        public int cNumDevices;
        public IntPtr pDevices;

        public void Reset()
        {
            dwSize = Marshal.SizeOf(this);
            cNumOfClasses = 0;
            prgClassOfDevices = IntPtr.Zero;
            pszInfo = null;
            hwndParent = IntPtr.Zero;
            fForceAuthentication = false;
            fShowAuthenticated = true;
            fShowRemembered = true;
            fShowUnknown = true;
            fAddNewDeviceWizard = false;
            fSkipServicesPage = false;
            pfnDeviceCallback = IntPtr.Zero;
            pvParam = IntPtr.Zero;
            cNumDevices = 0;
            pDevices = IntPtr.Zero;
        }

        public BLUETOOTH_DEVICE_INFO[] Devices
        {
            get
            {
                if (cNumDevices > 0)
                {
                    BLUETOOTH_DEVICE_INFO[] devs = new BLUETOOTH_DEVICE_INFO[cNumDevices];

                    for (int idevice = 0; idevice < cNumDevices; idevice++)
                    {
                        devs[idevice] = (BLUETOOTH_DEVICE_INFO)Marshal.PtrToStructure(new IntPtr(pDevices.ToInt64() + (idevice * Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)))), typeof(BLUETOOTH_DEVICE_INFO));
                    }

                    return devs;
                }
                return new BLUETOOTH_DEVICE_INFO[0];

            }
        }

        public BLUETOOTH_DEVICE_INFO Device
        {
            get
            {
                if (cNumDevices > 0)
                {
                    BLUETOOTH_DEVICE_INFO device = (BLUETOOTH_DEVICE_INFO)Marshal.PtrToStructure(pDevices, typeof(BLUETOOTH_DEVICE_INFO));
                    return device;
                }
                return new BLUETOOTH_DEVICE_INFO();
            }
        }
    }
}
